package com.loop.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * 迭代器遍历集合
 */
public class IteratorDemo {
    public static void main(String[] args) {
        Collection c = new ArrayList<>();
        c.add("a");
        c.add("b");
        c.add("c");
        c.add("d");

        Iterator iterator = c.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        //iterator.next();
        List list = new ArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
        list.clear();
        //IndexOutOfBoundsException
        //System.out.println(list.get(2));
    }
}
